﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace CapstoneMockup
{
    public partial class WeeklyTimeStampViewer : PhoneApplicationPage
    {
        private int _selectedItem;

        public WeeklyTimeStampViewer()
        {
            InitializeComponent();
            Loaded += FillInPage;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/TimeStampViewer.xaml", UriKind.Relative));
        }

        private void FillInPage(object sender, RoutedEventArgs args)
        {
            string selectedIndex;
            int index = 0;
            if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
            {
                index = int.Parse(selectedIndex);
                _selectedItem = index;
                DataContext = App.ViewModel.TimeStampItems[index];

            }
            totalHourTxtBlock.Text = App.ViewModel.TimeStampItems[index]._totalHours;
            if (App.ViewModel.TimeStampItems[index]._listOfHours.Count > 0)
                for (int i = App.ViewModel.TimeStampItems[index]._listOfHours.Count - 1; i >= 0; i--)
                {
                    startTimeListBox.Items.Add(App.ViewModel.TimeStampItems[index]._listOfHours[i].StartTime.ToShortDateString() + " " + App.ViewModel.TimeStampItems[index]._listOfHours[i].StartTime.ToShortTimeString());
                    endTimeListBox.Items.Add(App.ViewModel.TimeStampItems[index]._listOfHours[i].EndTime.ToShortDateString() + " " + App.ViewModel.TimeStampItems[index]._listOfHours[i].EndTime.ToShortTimeString());
                }
        }

        private void startTimeListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            endTimeListBox.SelectedIndex = startTimeListBox.SelectedIndex;
        }

        private void endTimeListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            startTimeListBox.SelectedIndex = endTimeListBox.SelectedIndex;
        }

        private void back_Click(object sender, RoutedEventArgs e)
        {
            if (NavigationService.CanGoBack)
                NavigationService.GoBack();
        }
    }
}